﻿<cfsilent>
	<cfscript>
	
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
	
		depId = sessionAdvice.getUserProp("teacherDepartment");
		
		sql = "SELECT 
					institute_id, institute_name 
				FROM 
					t_institute 
				WHERE 
					institute_id = :instituteId ";
					
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="instituteId", value=depId, cfsqltype="cf_sql_varchar" );
		
		rs_department = queryObj.execute( sql=sql ).getResult();

		sql = "SELECT 
				  	COUNT(*) count, t_course_catalog.cat_name, t_course_catalog.cat_id 
				FROM 
				  	t_course 
				  	INNER JOIN t_course_catalog ON t_course_catalog.cat_id = t_course.cat_id 
				WHERE 
				 	t_course.institute_id = :depId 
				 	AND 
				 	t_course.abandon = '0' 
				GROUP BY 
					t_course_catalog.cat_name, t_course_catalog.cat_id 
				ORDER BY 
				  	t_course_catalog.cat_id ";
					
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="depId", value=rs_department.institute_id, cfsqltype="cf_sql_varchar" );
		
		rs_catQuery = queryObj.execute( sql=sql ).getResult();

		sql = "SELECT 
				  	cat_id, cat_name 
				FROM 
				  	t_course_catalog 
				ORDER BY 
				 	cat_id  ";
					
		queryObj = new query( datasource=application.dnsSlave );
		rs_cat = queryObj.execute( sql=sql ).getResult();
		
		event.setArg("pageTitle", "教学运行基础数据 -课程库维护 - 任课单位概况 - " & rs_department.institute_name);
		
		targetArgs = structNew();
		structInsert(targetArgs, "DepID", rs_department.institute_id, true);
		
		currentTab = event.getArg("Cat", "00");
		
		if ( rs_catQuery.recordCount eq 1 ) {
			currentTab = event.getArg("Cat", catQuery[1][3]);
		}
		
		if ( rs_catQuery.recordCount eq 0 ) {
			currentTab = "labCreate";
		}
		
		/* 搜索课程 */
		keyword = event.getArg("Keywords");

		rs_search = queryNew("cid");
		
		if ( len(keyword) ) {
			
			sql = "SELECT 
						cid, course_name, course_code, course_credit, 
						period, period_theory, period_practice, period_computer, 
						period_week, mark_mode, institute_id, abandon 
					FROM 
					 	t_course 
					WHERE 
						institute_id = :depId 
						AND 
						(
							course_code LIKE :condition 
							or 
							course_name LIKE :condition
						)
					ORDER BY 
					 	course_name ";
					
			queryObj = new query( datasource=application.dnsSlave, maxrows=20 );
			queryObj.addParam( name="depId", value=depId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
			
			rs_search = queryObj.execute( sql=sql ).getResult();
		
			currentTab = "labSearch";
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('programSchema')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">培养方案</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i><cfoutput>#rs_department.institute_name#</cfoutput>课程开设情况
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
                        <cfloop query="rs_catQuery">
							<span <cfif currentTab eq rs_catQuery.cat_id>class="active"</cfif> id="labCourseCat<cfoutput>#rs_catQuery.cat_id#</cfoutput>" tabTarget="CourseCat<cfoutput>#rs_catQuery.cat_id#</cfoutput>"><cfoutput>#rs_catQuery.cat_name#</cfoutput></span>
						</cfloop>
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
                <cfloop query="rs_catQuery">
		
                   	<cfset sql = "SELECT 
										cid, course_name, course_code, course_credit, 
										period, period_theory, period_practice, period_computer, 
										period_week, mark_mode 
									FROM 
										t_course 
									WHERE 
										institute_id = :depId 
										AND 
										cat_id = :catId 
										AND 
										abandon = '0' 
									ORDER BY 
										course_name "/> 
                                        
                    <cfset queryObj = new query( datasource=application.dnsSlave )/> 
                    <cfset queryObj.addParam( name="depId", value=rs_department.institute_id, cfsqltype="cf_sql_varchar" )/>
                    <cfset queryObj.addParam( name="catId", value=rs_catQuery.cat_id, cfsqltype="cf_sql_char" )/> 
                    
                    <cfset rs_course = queryObj.execute( sql=sql ).getResult()/> 
                    
					<div id="CourseCat<cfoutput>#rs_catQuery.cat_id#</cfoutput>" class="tabContent">

						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="80">课程号</td>
									<td>课程</td>
									<td width="24" align="center">学分</td>
									<td width="50" align="center">计分</td>
									<td width="36" align="center">总学时</td>
									<td width="24" align="center">理论</td>
									<td width="24" align="center">实践</td>
									<td width="24" align="center">上机</td>
									<td width="36" align="center">周学时</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_course">
									<cfset row ++ />
									<cfset structInsert(targetArgs, "CID", rs_course.cid, true) />
									<tr class="editRows <cfif event.getArg('CID') eq rs_course.cid> lastEdited</cfif>">
										<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_course.course_code#</cfoutput></span></td>
										<td><cfoutput>#rs_course.course_name#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_course.course_credit, "0.0")#</cfoutput></span></td>
										<td align="center"><cfoutput>#dictAdvice.getMarkModeName(rs_course.mark_mode)#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_computer#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_course.period_week#</cfoutput></span></td>
										<td><a class="edit" href="<cfoutput>#buildURL('courseDetail', targetArgs)#</cfoutput>"></a></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					
					</div>
				</cfloop>
				
				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('programCourse')#</cfoutput>">
						<input type="hidden" name="TabID" value="labSearch" />
						
						<div class="label">
							<b>课程或课程号</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
                    <cfif rs_search.recordCount >
						
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="80">课程号</td>
									<td>课程</td>
									<td width="24" align="center">学分</td>
									<td width="50" align="center">计分</td>
									<td width="36" align="center">总学时</td>
									<td width="24" align="center">理论</td>
									<td width="24" align="center">实践</td>
									<td width="24" align="center">上机</td>
									<td width="36" align="center">周学时</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_search">
									<cfset row ++ />
									<cfset structInsert(targetArgs, "CID", rs_search.cid, true) />
									<cfset structInsert(targetArgs, "DepID", rs_search.institute_id, true) />
									<tr class="editRows <cfif rs_search.abandon eq "1"> cancelRow</cfif>">
										<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_search.course_code#</cfoutput></span></td>
										<td><cfoutput>#rs_search.course_name#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat(rs_search.course_credit, "0.0")#</cfoutput></span></td>
										<td align="center"><cfoutput>#dictAdvice.getMarkModeName(rs_search.mark_mode)#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_search.period#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_search.period_theory#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_search.period_practice#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_search.period_computer#</cfoutput></span></td>
										<td align="center"><span class="numeric"><cfoutput>#rs_search.period_week#</cfoutput></span></td>
										<td>
											<cfif rs_search.abandon eq "0">
												<a class="edit" href="<cfoutput>#buildURL('courseDetail', targetArgs)#</cfoutput>"></a>
											</cfif>
										</td>
									</tr>
								</cfloop>
							</tbody>
						</table>
						
					</cfif>
					
				</div>
				
			</div>
			
		</li>
	</ul>
</div>


